package accel.activities;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.TextView;
import accel.dataholders.Character;
public class NewCharacterActivity extends Activity {
	
	private Gallery portrait;
	private TextView name, str,ener,heal, cha, spe,desc,ls;
	private Character [] souls;
	private int soulId;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.newcharacter);
        name = (TextView)findViewById(R.id.name);
        str = (TextView)findViewById(R.id.strength);
        ener = (TextView)findViewById(R.id.energy);
        heal = (TextView)findViewById(R.id.health);
        cha = (TextView)findViewById(R.id.charisma);
        spe = (TextView)findViewById(R.id.speed);
        desc = (TextView)findViewById(R.id.description);
        ls = (TextView)findViewById(R.id.lspeed);
        souls = Character.getCharacters();
        portrait = (Gallery)findViewById(R.id.portrait);
        portrait.setAdapter(new ImageAdapter(this));
        portrait.setHorizontalFadingEdgeEnabled(true);
        portrait.setOnItemSelectedListener(new OnItemSelectedListener(){
        	public void onNothingSelected(AdapterView<?> a){}
        	
        	public void onItemSelected(AdapterView<?> adapter, View v, int i, long l)
        	{
        		name.setText(NewCharacterActivity.this.getString(souls[i].getName()));
        		str.setText(Integer.toString(souls[i].getStats().maxstrength));
        		ener.setText(Integer.toString(souls[i].getStats().maxenergy));
        		heal.setText(Integer.toString(souls[i].getStats().maxhealth));
        		cha.setText(Integer.toString(souls[i].getStats().maxcharisma));
        		spe.setText(Integer.toString(souls[i].getStats().maxspeed));
        		ls.setText(Integer.toString(souls[i].getStats().maxlearningspeed));
        		
        		desc.setText(NewCharacterActivity.this.getString(souls[i].getDesciption()));
        		
        		soulId = i;
        	}
        });
    }
	
	public void nextScreen(View v)
	{
		Character.instance = souls[soulId];
		//startActivity(new Intent(this, ChooseWeaponActivity.class));
		this.startActivityForResult(new Intent(this, ChooseWeaponActivity.class), 0);
	}
	
	@Override
	public void onActivityResult(int a, int b, Intent i)
	{
		if (b != RESULT_CANCELED)
			finish();
	}
	
	public class ImageAdapter extends BaseAdapter {
	    int mGalleryItemBackground;
	    private Context mContext;

	    private Integer[] pics = Character.getDrawablesArray();

	    public ImageAdapter(Context c) {
	        mContext = c;
	    }

	    public int getCount() {
	        return pics.length;
	    }

	    public Object getItem(int position) {
	        return position;
	    }

	    public long getItemId(int position) {
	        return position;
	    }

	    public View getView(int position, View convertView, ViewGroup parent) {
	        ImageView i = new ImageView(mContext);

	        i.setImageResource(pics[position]);

	        return i;
	    }
	}

}
